package cn.com.wangluotongxin.database.command;

import cn.com.wangluotongxin.admin.model.constants.DatabaseType;
import cn.com.wangluotongxin.common.exceptions.BadResponseException;
import cn.com.wangluotongxin.database.command.impl.MySqlCommandImpl;
import cn.com.wangluotongxin.database.command.impl.OracleSqlCommandImpl;
import cn.com.wangluotongxin.database.command.impl.SqlServerSqlCommandImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DatabaseCommandService {

    @Autowired
    private MySqlCommandImpl mySqlCommand;

    @Autowired
    private OracleSqlCommandImpl oracleSqlCommand;

    @Autowired
    private SqlServerSqlCommandImpl sqlServerSqlCommand;

    private DatabaseCommand client(Integer databaseType) {
        if(databaseType.equals(DatabaseType.MYSQL.getCode())) {
            return mySqlCommand;
        }else if(databaseType.equals(DatabaseType.ORACLE.getCode())) {
            return oracleSqlCommand;
        }else if(databaseType.equals(DatabaseType.SQL_SERVER.getCode())) {
            return sqlServerSqlCommand;
        }else {
            throw new BadResponseException("不支持的数据库");
        }
    }

    public void releaseDatabase( Integer databaseType, Integer databaseId, String domain, Integer port, String databaseName, String username, String password, Integer createUser, String createName, String channelId){
        client(databaseType).releaseDatabase(databaseId, domain, port, databaseName, username, password, createUser, createName, channelId);
    }
}
